from database.models import Videos
from utils import get_banner_details
from user.login import check_auth
from django.http import HttpRequest, JsonResponse, HttpResponse


def getlist(request: HttpRequest):
    token = request.GET.get('token')
    type = request.GET['type']
    user_id = -1

    if token and type(check_auth(token)) == int:
        user_id = check_auth(token)

    if type:
        return JsonResponse(
            {'payload': [get_banner_details(i) for i in Videos.objects.filter(video_type=type).all()]})
    return JsonResponse(
        {'payload': [get_banner_details(i) for i in Videos.objects.all()]})
